import debounce from "lodash/debounce";
let timer;
export const login = {
  created() {},
  methods: {
    //显示错误信息
    showError(val) {
      this.errors = val;
      setTimeout(() => {
        this.errors = "";
      }, 2000);
    },
    //去购买
    goBuy() {
      const link = [];
      const { version } = this.$fn.getUrlParams();
      link[3] = "http://www.zx093.com/other/dragonPro.htm?type=xl";
      link[4] = "http://www.zx093.com/other/dragonPro.htm?type=ql";
      link[5] = "http://www.zx093.com/other/dragonPro.htm?type=yl";
      link[6] = "http://www.zx093.com/other/dragonPro.htm?type=ylplus";
      window.prompt(
        "",
        `up://["open_browser",${Date.now()},{"url":"${link[version]}"}]`
      );
    },
    //游客
    tourist() {
      if (this.loading) return;
      window.prompt(
        "",
        `up://["web_user_login",${Date.now()},{"type":"guest_login","data":{}}]`
      );
    },
    buyBox(show) {
      this.buyShow = show;
    },
    //登录切换
    taggle(num) {
      num != false ? 1 : 0;
      this.logoType = num;
      this.noSubmit();
    },
    //现实图片验证码组件
    getAuthCode() {
      this.authShow = true;
    },
    cancel() {
      this.authShow = false;
    },
    //获取手机验证码
    confirm(authCode) {
      this.$refs.myFastLogin.getPhoneCode(authCode);
    },
    //取消登录
    noSubmit() {
      window.clearTimeout(timer);
      timer = null;
      this.loading = false;
      this.$refs.myCommonLogin.auto = false;
      window.localStorage.setItem("autoLogin", false);
    },
    //登录
    submit: debounce(function() {
      if (
        this.$refs.myCommonLogin.auto &&
        localStorage.getItem("autoLogin") == "false"
      ) {
        return this.$refs[
          ["myFastLogin", "myCommonLogin"][this.logoType]
        ].submit();
      }
      if (!this.$refs.myCommonLogin.auto) {
        return this.$refs[
          ["myFastLogin", "myCommonLogin"][this.logoType]
        ].submit();
      }
      this.loading = true;

      timer = window.setTimeout(() => {
        if (!this.loading) return;
        this.$refs[["myFastLogin", "myCommonLogin"][this.logoType]].submit();
        this.loading = false;
        window.clearTimeout(timer);
        timer = null;
      }, 1500);
    }, 400),
    //切换登录类型
    toggHeight(val) {
      this.toggle = val;
    },
    //切换登录/注册
    toggleType(num) {
      this.$emit("toggleType", num);
    },
    //清空登录input
    initialize() {
      this.$refs.myFastLogin.empty();
      this.$refs.myCommonLogin.empty();
    }
  }
};
